<?php

namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Post;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;//缓存
use Illuminate\Support\Facades\Gate;

class IndexController extends Controller
{

    public function index(Request $request)
    {
        //获取登录用户的ID
        $userAdminID =  auth()->guard('admin')->user()->auid;
        \Auth::loginUsingID($userAdminID);//获取id为1的user表的用户信息,只有用户表id为1的用户才有权限
        $post = Post::where('user_id',$userAdminID)->first();
        return view('admin.index',compact('post'));
    }


    public function systemInfo()
    {
        $memberInfo = DB::table('user')->count();
        $redfInfo = DB::table('redf')->count();
        $redsInfo = DB::table('reds')->count();
        $orderInfo = DB::table('cdorder')->where('pay_status',1)->count();
        $orderPrice = number_format(DB::table('cdorder')->where('pay_status',1)->sum('price') ,2, '.', '');
        $auditInfo = DB::table('shenhe')->where('status',0)->count();
        $walletInfo = number_format(DB::table('wallet')->sum('money') ,2, '.', '');
        $withdrawInfo = number_format(DB::table('tixian')->where('status',1)->sum('price') ,2, '.', '');

        return view('admin.systemInfo', compact('memberInfo','orderInfo','walletInfo','withdrawInfo','redfInfo','redsInfo','auditInfo','orderPrice'));
    }


    /*
     * 后台管理关联查询
     * */

    public function userId($status){

        if($status==1){
            $data = DB::table('redf')->where('status', 1)->paginate(10);

        }elseif ($status==2){
            $data = DB::table('redf')->where('status', 0)->paginate(10);

        }elseif ($status==3){
            $data = DB::table('redf')->where('pay_type', 0)->paginate(10);

        }elseif ($status==4){
            $data = DB::table('redf')->where('pay_type',1)->paginate(10);
        }elseif ($status==5){
            $data = DB::table('redf')->where('sign',2)->paginate(10);
        }elseif ($status==6){
            $data = DB::table('redf')->where('sign',1)->paginate(10);
        }
        return view('admin.red.redf',compact('data'));

    }


// 清除所有缓存
    public function delHc()
    {

        Cache::flush();
        echo "<script>alert('清除成功!');</script>";
    }


}
